﻿using System.Windows.Forms;

namespace TestServices
{
    public partial class MainForm : Form
    {
        private readonly ServiceProvider serviceProvider = new ServiceProvider();
        private readonly DialogBrain dialogBrain;

        public MainForm()
        {
            dialogBrain = new DialogBrain(serviceProvider);
            InitializeComponent();
            serviceProvider.AddService(typeof(ICalc),new Calc());
            serviceProvider.AddService(typeof(IConvertor), new Convertor());
        }


        private void Calculate()
        {
            labelResult.Text = dialogBrain.GetResult(textBoxX.Text, textBoxY.Text);
        }

        private void buttonCalc_Click(object sender, System.EventArgs e)
        {
            Calculate();
        }

        private void textBoxY_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Calculate();
            }
        }

        private void buttonOk_Click(object sender, System.EventArgs e)
        {
            Close();
        }

    }
}
